package com.li.springbootproject.config.requestlimit.counterlimit;

import java.util.concurrent.TimeUnit;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/12/26 10:16
 */
public abstract class CounterLimit {

    // 限制时间
    protected long limitTime;
    // 限制时间单位
    protected TimeUnit timeUnit;
    // 时间段内限制请求的次数
    protected int limitCount;
    // 当前是否为受限制状态
    protected volatile boolean limited;

    public CounterLimit(long limitTime, TimeUnit timeUnit, int limitCount) {
        this.limitTime = limitTime;
        this.timeUnit = timeUnit;
        this.limitCount = limitCount;
    }

    protected CounterLimit() {
    }

    /**
     * 计数器加 1 返回 true 能够正常访问接口，false 表示访问受限
     *
     * @return
     */
    protected abstract boolean count();

}
